import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../interface/room_page_model.dart';
import '../../interface/room_plugin.dart';
import '../../manager/room_manager.dart';
import 'room_life_cycle_mixin.dart';
import 'room_page_builder.dart';

class ChatRoomMainPage extends StatefulWidget {
  final int? type;
  final int? comId;
  const ChatRoomMainPage({super.key, this.type, this.comId});

  @override
  State<ChatRoomMainPage> createState() => _ChatRoomMainPageState();
}

class _ChatRoomMainPageState extends State<ChatRoomMainPage>
    with
        WidgetsBindingObserver,
        SingleTickerProviderStateMixin,
        RoomLifecycleMixin {
  RoomPageBuilder get builder {
    RoomPlugin? plugin = RoomManager.instance.getTemplatePlugin();

    RoomPageBuilder? pageBuilder = plugin?.createPageBuilder(context);
    pageBuilder ??= RoomPageBuilder(context);
    return pageBuilder;
  }

  @override
  Widget build(BuildContext context) {
    return Consumer<RoomPageModel>(builder: (context, model, child) {
      return Scaffold(
        //键盘弹出不积压上部内容
        resizeToAvoidBottomInset: false,
        key: model.mainKey,
        // endDrawer: RoomDrawerPage(
        //     // currentSelectIndex: DfInstance.indexBasedRoomType(
        //     //     model.channel?.roomLabel.name ?? ''),
        //     ),
        onEndDrawerChanged: (isOpen) {
          model.updateIsShowingEndDrawer(isOpen);
        },
        backgroundColor: const Color(0xFF120037),
        body: builder.body,
      );
    });
  }
}
